<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title></title>
    <script src="../static/js/jquery/jquery-2.1.4.min.js" type="text/javascript"></script>
    <script src="../static/layui/layui.js" type="text/javascript"></script>
    <script src="../static/js/index/index.js" type="text/javascript"></script>
    <script src="../static/js/index/freezeheader.js" type="text/javascript"></script>
    <script src="../static/layui/lay/modules/layer.js" type="text/javascript"></script>
    <script src="../static/js/index/sliders.js" type="text/javascript"></script>
    <script src="../static/js/index/html5.js" type="text/javascript"></script>
    <link rel="stylesheet" href="../static/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="../static/layui/css/modules/layer/default/layer.css"/>
    <link rel="stylesheet" href="../static/css/global.css"/>
    <link rel="stylesheet" href="./css/amazeui.min.css"/>
    <link rel="stylesheet" href="./css/admin.css"/>
    <link rel="stylesheet"
          href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
    <%--<script type="text/javascript" src="js/jquery-3.4.1.min.js"></script>--%>
    <script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
    <script
            src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>

    <link rel="stylesheet" type="text/css"
          href="https://www.layuicdn.com/layui/css/layui.css"/>

    <script type="text/javascript" src="js/layer.js"></script>
    <link rel="stylesheet" href="css/layer.css">
</head>
<body>
<div class="admin-content-body">
    <div class="am-cf am-padding am-padding-bottom-0">
        <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">教师管理</strong>
            <small></small>
        </div>
    </div>
    <hr>
    <div class="am-g">
        <div class="am-u-sm-12 am-u-md-6">
            <div class="am-btn-toolbar">
                <div class="am-btn-group am-btn-group-xs">
                   <%-- <a href="javascript:void(0)" class="am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only"
                       onclick="updatePwd('新增')">新增</a>--%>

                    <a class="am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only"
                       href="/admin/teacher/jump">新增</a>
                </div>
            </div>
        </div>
        <div class="am-u-sm-12 am-u-md-4">
            <div class="layui-form-item">
                <div class="layui-input-inline" style="width:65%;">
                    <input type="text" id="keyName" name="keyContent" lay-verify="required" placeholder="请输入关键字"
                           class="layui-input">
                </div>
                <button class="layui-btn" onclick="getMessage();">搜索</button>
            </div>
        </div>
    </div>
    <div class="am-g">
        <div class="am-u-sm-12">
            <form class="am-form">
                <table class="am-table am-table-striped am-table-hover table-main">
                    <thead>
                    <tr>
                        <th class="table-type">教师ID</th>
                        <th class="table-type">教师工号</th>
                        <th class="table-type">教师姓名</th>
                        <th class="table-type">教师简介</th>
                        <th class="table-type">教师性别</th>
                        <th class="table-type">教师职称</th>
                        <th class="table-type">教师所教科目</th>
                        <th class="table-type">教师学历</th>
                        <th class="table-type">教师email</th>
                        <th class="table-type">操作</th>
                    </tr>
                    </thead>
                    <tbody id="teacherResult">
                    <c:forEach items="${teachers}" var="teacher">
                        <tr>
                            <td>${teacher.teacherId}</td>
                            <td class="am-hide-sm-only">${teacher.teacherNumber}</td>
                            <td class="am-hide-sm-only">${teacher.teacherName}</td>
                            <td class="am-hide-sm-only">${teacher.teacherBrief}</td>
                            <c:set var="cnt" scope="session"
                                   value="${teacher.teacherSex}"></c:set>
                            <c:if test="${cnt==0}">
                                <td class="am-hide-sm-only">男</td>
                            </c:if>
                            <c:if test="${cnt==1}">
                                <td class="am-hide-sm-only">女</td>
                            </c:if>
                            <td class="am-hide-sm-only">${teacher.teacherPost}</td>
                            <td class="am-hide-sm-only">${teacher.teacherSubject}</td>
                            <td class="am-hide-sm-only">${teacher.teacherDegree}</td>
                            <td class="am-hide-sm-only">${teacher.teacherEmail}</td>
                            <td>
                                <div class="am-btn-toolbar" >
                                    <div class="am-btn-group am-btn-group-xs">
                                        <a class="am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only"
                                           href="/admin/updTeacher/${teacher.teacherNumber}">编辑</a>
                                    </div>
                                </div>
                            </td>
                            <div class="modal fade" id="myModal" tabindex="-1" role="dialog"
                                 aria-labelledby="myModalLabel" aria-hidden="true">
                                <div class="modal-dialog">
                                    <div class="modal-content">
                                        <div class="modal-header">
                                            <button type="button" class="close" data-dismiss="modal"
                                                    aria-hidden="true">&times;
                                            </button>
                                            <h4 class="modal-title" id="myModalLabel">编辑</h4>
                                        </div>
                                        <div class="modal-body">
                                            <form class="layui-form" method="get" action="/admin/teacher/update"
                                                  id="formSum"
                                                  name="formSum">

                                                <div class="layui-form-item">
                                                    <label for="L_username" class="layui-form-label">教师工号</label>
                                                    <div class="layui-input-inline">
                                                        <input type="text" name="userNumber" lay-verify="required"
                                                               autocomplete="off"
                                                               value="${teacher.teacherNumber}"
                                                               class="layui-input" readonly placeholder="请输入教师工号">
                                                    </div>
                                                </div>

                                                <div class="layui-form-item">
                                                    <label for="L_username" class="layui-form-label">老师姓名</label>
                                                    <div class="layui-input-inline">
                                                        <input type="text" name="username" lay-verify="required"
                                                               autocomplete="off"
                                                               value="${teacher.teacherName}"
                                                               class="layui-input" readonly placeholder="请输入老师姓名">
                                                    </div>
                                                </div>


                                                <div class="layui-form-item">
                                                    <label for="L_username" class="layui-form-label">老师性别</label>
                                                    <div class="layui-input-inline">
                                                        <div class="layui-inline">
                                                            <div class="layui-input-inline">
                                                                <c:set var="sex" scope="session"
                                                                       value="${teacher.teacherSex}"></c:set>
                                                                <c:if test="${sex==1}">
                                                                    <input type="radio" name="sex" value="1" checked
                                                                           title="男" readonly>
                                                                    <input type="radio" name="sex" value="0" title="女"
                                                                           readonly>
                                                                </c:if>
                                                                <c:if test="${sex==0}">
                                                                    <input type="radio" name="sex" value="1" title="男"
                                                                           readonly>
                                                                    <input type="radio" name="sex" value="0" checked
                                                                           title="女" readonly>
                                                                </c:if>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                                <div class="layui-form-item">
                                                    <label for="L_email" class="layui-form-label">邮箱</label>
                                                    <div class="layui-input-inline">
                                                        <input type="text" name="email" lay-verify="email"
                                                               autocomplete="off"
                                                               class="layui-input" value="${teacher.teacherEmail}"
                                                               placeholder="请输入邮箱">
                                                    </div>
                                                </div>
                                                <div class="layui-form-item">
                                                    <label for="L_username" class="layui-form-label">教师简介</label>
                                                    <div class="layui-input-inline">
                                                        <input type="text" name="teacherBrief" lay-verify="required"
                                                               autocomplete="off"
                                                               value="${teacher.teacherBrief}"
                                                               class="layui-input" placeholder="请输入教师简介">
                                                    </div>
                                                </div>
                                                <div class="layui-form-item">
                                                    <label for="L_username" class="layui-form-label">教师职称</label>
                                                    <div class="layui-input-inline">
                                                        <input type="text" name="teacherPost" lay-verify="required"
                                                               autocomplete="off"
                                                               value="${teacher.teacherPost}"
                                                               class="layui-input" placeholder="请输入教师职称">
                                                    </div>
                                                </div>
                                                <div class="layui-form-item">
                                                    <label for="L_username" class="layui-form-label">教师所教科目</label>
                                                    <div class="layui-input-inline">
                                                        <input type="text" name="teacherSubject" lay-verify="required"
                                                               autocomplete="off"
                                                               value="${teacher.teacherSubject}"
                                                               class="layui-input" placeholder="请输入教师所教科目">
                                                    </div>
                                                </div>
                                                <div class="layui-form-item">
                                                    <label for="L_username" class="layui-form-label">教师学历</label>
                                                    <div class="layui-input-inline">
                                                        <input type="text" name="teacherDegree" lay-verify="required"
                                                               autocomplete="off"
                                                               value="${teacher.teacherDegree}"
                                                               class="layui-input" placeholder="教师学历">
                                                    </div>
                                                </div>
                                            </form>
                                        </div>
                                        <div class="modal-footer">
                                            <button type="button" class="btn btn-default" data-dismiss="modal">关闭
                                            </button>
                                            <button type="button" class="urb btn btn-primary">提交更改</button>
                                        </div>
                                    </div>
                                    <!-- /.modal-content -->
                                </div>
                                <!-- /.modal -->
                            </div>
                            <td>
                                <div class="am-btn-toolbar">
                                    <div class="am-btn-group am-btn-group-xs">
                                        <a class="am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only"
                                            <%--href="/teacher/del/${teacher.teacherId}"--%>
                                           onclick="delTeacher(${teacher.teacherId})">删除</a>
                                    </div>
                                </div>
                            </td>
                        </tr>

                    </c:forEach>
                    </tbody>
                </table>
                <%--	<div class="am-cf">
                        共 15 条记录
                        <div class="am-fr">
                            <ul class="am-pagination">
                                <li class="am-disabled">
                                    <a href="#">«</a>
                                </li>
                                <li class="am-active">
                                    <a href="#">1</a>
                                </li>
                                <li>
                                    <a href="#">2</a>
                                </li>
                                <li>
                                    <a href="#">3</a>
                                </li>
                                <li>
                                    <a href="#">4</a>
                                </li>
                                <li>
                                    <a href="#">5</a>
                                </li>
                                <li>
                                    <a href="#">»</a>
                                </li>
                            </ul>
                        </div>
                    </div>--%>
                <hr>
            </form>
        </div>
    </div>
</div>
<script>
    alert(点击了修改)
</script>
<script>
    var nowdatas;
    var inputName;

    function getMessage() {
        inputName = $("#keyName").val();
        $.ajax({
                type: "get",
                url: "/admin/teacher/search",
                data: {"keyContent": inputName},
                dataType: 'json',
                success: function (data) {
                    if (data.length == 0) {
                        alert("没有搜索到对应的内容");
                    }
                    nowdatas = data;
                    add();
                }
            }
        )
    }

    function delTeacher(teacherId) {
        inputName = teacherId;
        $.ajax({
                type: "get",
                url: "/teacher/del",
                data: {"teacherId": inputName},
                dataType: 'json',
                success: function (data) {
                  //  location.reload();
                    parent.location.reload();
                    alert("删除成功！");
                }
            }
        )
    }

    function add() {
        $('#teacherResult').empty();
        for (var i = 0; i < nowdatas.length; i++) {
            str1 = '<tr><td>' + (i + 1) + '</td><td>' +
                nowdatas[i]['teacherNumber']
                + '</td><td>' +
                nowdatas[i]['teacherName']
                + '</td><td>' +
                nowdatas[i]['teacherBrief']
                + '</td><td>' +
                nowdatas[i]['teacherSex']
                + '</td><td>' +
                nowdatas[i]['teacherPost']
                + '</td><td>' +
                nowdatas[i]['teacherSubject']
                + '</td><td>' +
                nowdatas[i]['teacherDegree']
                + '</td><td>' +
                nowdatas[i]['teacherEmail']
                + '</td><td></td><td><div class="am-btn-toolbar" ><div class="am-btn-group am-btn-group-xs"><a class="am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only" href="/admin/updTeacher/' + nowdatas[i]['teacherNumber'] + '">编辑</a></div></div></td><td><div class="am-btn-toolbar"><div class="am-btn-group am-btn-group-xs"><dd></dd><a href="/teacher/del/' + nowdatas[i]['teacherId'] + '">删除</a></div></div></td>' +
                +'</tr>';
            $('#teacherResult').append(str1);
        }
    }
</script>
</body>
<script type="text/javascript" src="myplugs/js/plugs.js">
</script>
<script type="text/javascript">
    //添加编辑弹出层
    function updatePwd(title) {
        $.jq_Panel({
            title: title,
            iframeWidth: 500,
            iframeHeight: 750,
            url: "teacherSet.jsp"
        });
    }
</script>
<script src="js/layui.js"></script>
<script>
    //JavaScript代码区域
    layui.use('element', function () {
        var element = layui.element;

    });
</script>
</html>